<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.kingdee.bos.Context" %>
<%@ page import="com.kingdee.eas.cp.common.web.util.WebContextUtil" %>
<%@ page import="com.kingdee.eas.base.attachment.AttachmentFactory" %>
<%@ page import="com.kingdee.eas.base.attachment.AttachmentInfo" %>
<%@ page import="javax.servlet.ServletOutputStream" %>
<%@ page import="com.kingdee.bos.dao.ormapping.ObjectUuidPK" %>
<%@ page import="com.kingdee.util.StringUtils" %>
<%@ page import="com.kingdee.eas.base.attachment.util.AttachmentUtils" %>
<%@ page import="com.kingdee.bos.util.BOSUuid" %>
<%@ page import="java.lang.Exception" %>
<%
Context ctx = WebContextUtil.getEasContext(request);
String id = request.getParameter("bosID");
if(!StringUtils.isEmpty(id))
{
	id = AttachmentUtils.init().checkID(id);
	AttachmentInfo info = null;
	try {
            BOSUuid.read(id);
			if(ctx!=null){
			info = AttachmentFactory.getLocalInstance(ctx).getAttachmentInfo(new ObjectUuidPK(id));
			}else{
            info = AttachmentFactory.getRemoteInstance().getAttachmentInfo(new ObjectUuidPK(id));
			}
        } catch (Exception e) {
            info = AttachmentFactory.getRemoteInstance().getAttachmentInfo("where attachID = '"+id+"'");
        }
	
	response.setHeader("Content-disposition","attachment;filename=" + URLEncoder.encode(info.getName() + "." + info.getSimpleName(), "utf-8"));
	ServletOutputStream output = null;
	try{
	   byte size[] = info.getFile();
	   output = response.getOutputStream();
	   output.write(size);
	}catch(Exception e){
	   System.out.print(e.getMessage());
	}finally{
	   try{
	    output.flush();
	    output.close();
	   }catch(Exception ex){
	  
	   }
	}
}
%>